package com.intelligence.config.amqpConfig;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author : RulerWood
 * @Data : 2024/5/23 - 21:39
 */
@Configuration
public class RabbitMqConfig {
    /**
     * 从属于设备的队列
     * @return
     */
    @Bean(value = "queueCloudDevice")
    public Queue queueCloudDevice() {
        return QueueBuilder.durable("device-cloud-queue").build();
    }

    @Bean(value = "exchangeCloudDevice")
    public Exchange exchangeCloudDevice() {
        return ExchangeBuilder.directExchange("device-cloud-exchange").build();
    }

    @Bean
    public Binding bindingCloudDevice(@Qualifier(value = "queueCloudDevice") Queue queue,
                                      @Qualifier(value = "exchangeCloudDevice") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("device-cloud-routingKey").noargs();
    }

    /**
     * 通知发布的队列
     * @return
     */
    @Bean(value = "queuePublisher")
    public Queue queuePublisher() {
        return QueueBuilder.durable("Publisher-queue").build();
    }

    @Bean(value = "exchangePublisher")
    public Exchange exchangePublisher() {
        return ExchangeBuilder.directExchange("Publisher-exchange").build();
    }

    @Bean
    public Binding bindingPublisher(@Qualifier(value = "queuePublisher") Queue queue,
                                      @Qualifier(value = "exchangePublisher") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("Publisher-routingKey").noargs();
    }

    /**
     * 设备采集异常队列
     */
    @Bean(value = "queueDeviceGatherError")
    public Queue queueDeviceGatherError() {
        return QueueBuilder.durable("gather-error-queue").build();
    }

    @Bean(value = "exchangeDeviceGatherError")
    public Exchange exchangeDeviceGatherError() {
        return ExchangeBuilder.directExchange("gather-error-exchange").build();
    }

    @Bean
    public Binding bindingDeviceGatherError(@Qualifier(value = "queueDeviceGatherError") Queue queue,
                                    @Qualifier(value = "exchangeDeviceGatherError") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("gather-error-routingKey").noargs();
    }


}
